<?php

namespace app\admin\controller\api;

use think\admin\Controller;
use think\admin\model\SystemSites;
use think\admin\model\SystemDownload;
use think\exception\HttpResponseException;

/**
 * 站点接口
 * @class Sites
 * @package app\admin\controller\api
 */
class Sites extends Controller
{
    /**
     * 
     * @login true
     */
    public function index()
    {
      $data = array();
      $siteLists = SystemSites::mQuery()->db()->select();
      foreach ($siteLists as $key => $value) {
        $data[$key]['name'] = $value['site_name'];
        $data[$key]['value'] = $value['id'];
      }
      return json(['msg'=>'接收成功','data'=>$data]);
    }
    /**
     * 
     * @login true
     */
    public function edit()
    {
      $data = array();
      $siteLists = SystemSites::mQuery()->db()->select();
      foreach ($siteLists as $key => $value) {
        $data[$key]['name'] = $value['site_name'];
        $data[$key]['value'] = $value['id'];
      }
      $initLists = SystemDownload::mQuery()->db()->where('id',$_REQUEST['id'])->find();
      $initLists = $array = explode(',', $initLists['reseed_sites']);
      if($initLists){
        return json(['msg'=>'接收成功','data'=>$data,'initdata'=>$initLists]);
      }else{
        return json(['msg'=>'找不到下载器',]);
      }
      
    }
}